import java.math.BigInteger;
import java.util.Scanner;

public class demo01 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String num=sc.nextLine();
        String n= new BigInteger(num,9).toString(10);
        System.out.println(n);
    }
}
